package com.example.xutils1.utils;

import com.alibaba.fastjson.JSON;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;

/**
 * 鑷姩灏嗘墍璇锋眰寰楃殑鏁版嵁瑙ｆ瀽鎴愭墍缁欏畾鐨凜lass绫诲瀷鐨勭被
 * 
 * @author bm
 */
public abstract class RequestCallBackEx<T> extends RequestCallBack<String> {

	private Class<T> mCls;

	public RequestCallBackEx(Class<T> cls) {
		mCls = cls;
	}

	@Override
	public void onSuccess(ResponseInfo<String> responseInfo) {
		try {
			String jsonString = responseInfo.result;
			T obj = JSON.parseObject(jsonString, mCls);
			onSuccess(obj);
		} catch (Exception e) {
			onFailure(new HttpException(e.toString()), e.toString());
		}
	}

	public abstract void onSuccess(T obj);
}